Skip to content

(closes #1312) fix scalar array functionality - #3520

Open
mo-alistairp wants to merge 18 commits into
masterfrom
1312_fix_scalar_array_functionality_invoke_call
Open

(closes #1312) fix scalar array functionality#3520
mo-alistairp wants to merge 18 commits into
masterfrom
1312_fix_scalar_array_functionality_invoke_call

Conversation

@mo-alistairp

@mo-alistairp mo-alistairp commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

The gh_scalar_array functionality is not working as intended (#1312). The generated kernel subroutine includes an array of the extents of the dimensions of the scalar array in the the list of arguments. This isn't being generated in the corresponding invoke call. As a result the mismatch in arguments causes build errors when gh_scalar_array is used.

This was likely because kern_call_invoke_arg_list.py was missed. This wasn't picked up by testing because the algorithm layer doesn't get compiled. As a way to verify that this functionality does work I'll also add an example using gh_scalar_array that gets compiled to ensure that it builds correctly. I'll probably also add a bit more documentation to aid users.

@mo-alistairp mo-alistairp self-assigned this Jul 31, 2026
@mo-alistairp mo-alistairp added bug in progress LFRic Issue relates to the LFRic domain LFRic PSyKAl-lite Issue related to removal of PSyKAl-lite code in LFRic labels Jul 31, 2026
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fed76e4) to head (07351fc).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #3520   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          399       399           
  Lines        56462     56473   +11     
=========================================
+ Hits         56462     56473   +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@arporter arporter assigned arporter and unassigned mo-alistairp Sep 4, 2026
@arporter
arporter marked this pull request as ready for review September 4, 2026 11:43
@arporter

arporter commented Sep 4, 2026

Copy link
Copy Markdown
Member

I've taken this on from Alistair as he has moved roles.

This is ready for a first look now. It's quite LFRic heavy so one for @sergisiso or @hiker. (Although I'm now scared that Sergi will use Codex...) We now have an example of the functionality that compiles and links so are in much better shape.

@christophermaynard or @stevemullerworth - the one thing I omitted to ask Alistair for was a 'science' contact to help with testing of this functionality. Could you help here?

@sergisiso sergisiso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arporter The changes look good and the generated code looks correct.

One problem I see is that the array_scalars handling is missing in some places for instance in: src/psyclone/domain/lfric/kernel/meta_args_metadata.py:81 and the kern_call_invoke_arg_list.py that I mentioned in an inline comment. I am wondering now if this is a matter of the old/new metadata path. In which case I might prefer to keep the new path as is, since I have changed it substancially in another PR, but we may want to document the divergence.


compile: transform
@echo "No compilation supported for lfric/eg1"
single_invoke_alg.f90 single_invoke_psy.f90: single_invoke.x90

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only comment from Codex was that modifying ../code/testkern_mod.F90 should retrigger this target as the psy-layer could be different. It is right (and very smart again, the kernel is not explicitly mentioned here so it knows what single_invoke.x90 have and that kernel metadata changes can produce changes in single_invoke_psy.f90 which is the output of this target).

However, this is a mistake that we have consistently across all examples and I would not explictly mention the specific kernel in the Makefile rule, which would fix the issue, but this would duplicate what is encoded inside the alg file. We could maybe mention the whole directory since it is explictly mentioned in the command, but make it worse the "-d" parameter is recursive. So maybe the right solution is something like https://stackoverflow.com/questions/25005637/makefile-rule-depend-on-directory-content-changes ?

I don't know. I will let you decide if its worth fixing, or leave it be, or just create a separate issue.

Comment on lines 91 to 113
def generate(self, var_accesses=None):
''' Ensures that our internal lists of arguments of various
types are reset (as calling generate() populates them) before calling
this method in the parent class.

:param var_accesses: optional VariablesAccessMap instance to store
the information about variable accesses.
:type var_accesses: :py:class:`psyclone.core.VariablesAccessMap`
'''
self._fields = []
self._scalars = []
self._qr_objects = []
self._operators = []
self._halo_depth = None
super().generate(var_accesses)

def scalar(self,
scalar_arg: "LFRicKernelArgument",
var_accesses: Optional[VariablesAccessMap] = None
) -> None:
'''
Add the necessary argument for a scalar quantity as well as an
appropriate Symbol to the SymbolTable.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently we don't keep a separate list of scalar_arrays arguments here, so Codex recons they still go through the scalar method and creates a scalar DataSymbol, ignoring scalar_arg._array_ndims

However the generated code in the output is correct. I am always confuse by this class but I cannot see scalar arrays handled anywhere. How come this doesn't matter?

" subroutine invoke_0(f1, real_array, logical_array, integer_array, "
"dims_integer_array, a, f2, f3, f4, b, dims_real_array, "
"dims_logical_array, dims_integer_array_1)\n"
"dims_integer_array, a, f2, f3, f4, b)\n"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "dim_integer_array" here had me confused until I read the algorithm file which has:

  ! Include dims_integer_array as a scalar value to check that the
  ! generated code names do not clash
  call invoke(                                                                                       &
       testkern_scalar_array_type(f1, real_array, logical_array, integer_array, dims_integer_array), &

Maybe we can repeat the comment here to make clear why we recieve this name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug LFRic PSyKAl-lite Issue related to removal of PSyKAl-lite code in LFRic LFRic Issue relates to the LFRic domain reviewed with actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants